package nezumi.gui;

import java.awt.Component;
import java.awt.Graphics2D;
import java.awt.Point;
import java.io.IOException;
import java.util.logging.Logger;

import nezumi.state.State;

public abstract class ASpriteEntity extends AEntity {

	private static final Logger logger = Logger.getLogger(ASpriteEntity.class
			.getName());

	protected final Sprite sprite;

	public ASpriteEntity(String spriteRef, State state, Component enclosingComp) {
		super(state, enclosingComp);
		assert spriteRef != null : "spriteRef = " + spriteRef;

		Sprite sprite = null;
		try {
			sprite = SpriteStore.get().getSprite(spriteRef);
		} catch (IOException e) {
			logger.severe(String.format("Error loading sprite from %s: %s",
					spriteRef, e.getMessage()));
		}

		this.sprite = sprite;
	}

	protected abstract Point getLocation();

	public void draw(Graphics2D g) {
		final Point loc = this.translatePoint(getLocation());
		sprite.drawCentered(g, loc.x, loc.y);
	}
}
